﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;

namespace Infrastructure.Aspect.Dynamic
{
    public class CustomExpandoObject : DynamicObject
    {


        Dictionary<string, object> dictionary = new Dictionary<string, object>();
           
        public int Count
        {
            get
            {
                return dictionary.Count;
            }
        }

        public CustomExpandoObject()
        { }


        public CustomExpandoObject Build(string key, object value)
        {
            dictionary.Add(key.ToLower(), value);
            return this;
        }
     
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {           
            string name = binder.Name.ToLower();           
            return dictionary.TryGetValue(name, out result);
        }        
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            dictionary[binder.Name.ToLower()] = value;
            return true;
        }
    }
}
